package com.franklin.ideaplugin.easytesting.ui.execute;

import com.franklin.ideaplugin.api.ui.editor.CustomEditor;
import com.franklin.ideaplugin.api.ui.editor.FormatCustomJsonEditor;
import com.intellij.psi.PsiParameter;
import org.jetbrains.annotations.NotNull;

/**
 * @author Ye Junhui
 * @since 2023/7/2 12:21
 */
public class NormalParameterFormProvider implements IParameterFormProvider {
    @Override
    public boolean isTarget(@NotNull Object defaultValue) {
        return true;
    }

    @Override
    public ParameterTextComponent getForm(PsiParameter psiParameter, Object defaultValueOfPsiType, Object defaultValue) {
        String title = psiParameter.getType().getPresentableText() + " " + psiParameter.getName();
        CustomEditor customEditor = new CustomEditor(psiParameter.getProject(), CustomEditor.TEXT_FILE_TYPE);
        customEditor.setText(defaultValue.toString());
        customEditor.setPsiType(psiParameter.getType());
        FormatCustomJsonEditor formatCustomEditor = new FormatCustomJsonEditor(title,customEditor);
        return new ParameterTextComponent(formatCustomEditor.getMainPanel()) {
            @Override
            public String getText() {
                return customEditor.getText();
            }
        };
    }
}
